package com.example.pathprotectsystem.utils;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateTimeChangeUtil {
    public static String change(String oldDate){
        String inputDateStringWithoutZ = oldDate.substring(0, oldDate.length() - 1);
        // 将 "T" 替换为空格
        String outputDateString = inputDateStringWithoutZ.replace("T", " ");
        // 定义输入字符串的格式
        DateTimeFormatter inputDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
        // 解析输入字符串，生成 LocalDateTime 对象
        LocalDateTime localDateTime = LocalDateTime.parse(outputDateString, inputDateTimeFormatter);
        //解决时差，向后延8个小时
        Duration duration = Duration.ofHours(8);
        LocalDateTime laterDateTime = localDateTime.plus(duration);
        // 定义输出字符串的格式
        DateTimeFormatter outputDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 格式化 LocalDateTime 对象，生成输出字符串
        String formattedOutputString = laterDateTime.format(outputDateTimeFormatter);
        return formattedOutputString;
    }
}
